package com.concurrent.service.impl;

import com.concurrent.dao.UserMapper;
import com.concurrent.dao.UserRoleMapper;
import com.concurrent.model.Role;
import com.concurrent.model.User;
import com.concurrent.model.UserRole;
import com.concurrent.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class UserServiceImpl  implements UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    UserRoleMapper userRoleMapper;
    public List<User> selectList(){
        Map<String,Object> param = new HashMap<>();
        param.put("status",1);
        return userMapper.selectByMap(param);
    }

    public User  selectOneByUsername(String username){
        return userMapper.selectOne(new User(username));
    }

    public List<UserRole>  selectRoleByUsername(String username){
        User user=userMapper.selectOne(new User(username));
        Map<String,Object> param = new HashMap<>();
        param.put("uid",user.getId());
        return userRoleMapper.selectByMap(param);
    }
}
